package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理模块")
public class NursingProjectController {

    @Resource
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation(value = "分页查询护理项目", notes = "根据页码、每页数量、名称和状态分页查询护理项目列表")
    public ResponseResult<NursingProject> selectByPage(
            @ApiParam(value = "页码", required = true) Integer pageNum,
            @ApiParam(value = "每页数量", required = true) Integer pageSize,
            @ApiParam(value = "名称") String name,
            @ApiParam(value = "状态") Integer status) {

        PageResponse<NursingProjectVo> nursingProjectResponseResult = nursingProjectService.selectByPage(pageNum, pageSize, name, status);
        return ResponseResult.success(nursingProjectResponseResult);
    }

    @PostMapping
    @ApiOperation(value = "新增护理项目", notes = "新增护理项目")
    public ResponseResult addProject(
            @ApiParam(value = "护理项目信息", required = true)
            @RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.addProject(nursingProjectDto);
        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理项目")
    public ResponseResult<NursingProjectVo> selectById(
            @ApiParam(value = "护理项目id", required = true)
            @PathVariable Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.selectById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    @PutMapping("/{id}")
    @ApiOperation("更新护理项目")
    public ResponseResult updateproject(
            @ApiParam(value = "护理项目id", required = true)
            @RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.updateproject(nursingProjectDto);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用护理项目")
    public ResponseResult isEnable(
            @ApiParam(value = "护理项目id", required = true)
            @PathVariable("id") Long id,
            @ApiParam(value = "状态", required = true)
            @PathVariable("status") Integer status) {
        nursingProjectService.ture_false(id, status);
        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deleteproject(
            @ApiParam(value = "护理项目id", required = true)
            @PathVariable("id") Long id) {
        nursingProjectService.deleteproject(id);
        return ResponseResult.success();
    }


    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProject>> selectAll() {
        return ResponseResult.success(nursingProjectService.selectAll());
    }
}
